<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_transaksi extends MY_Controller {

    function __construct() {
        parent::__construct();

        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");

        $this->mpemesanan = new M_pemesanan();
        $this->mpemesanandet = new M_pemesanan_det();
        $this->mprodukdet = new M_produk_det();
    }

    function index() {

        $data['title'] = 'Daftar Data Transaksi';
        $data['list_pemesanan'] = $this->mpemesanan->select_data();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function view_det($id = NULL) {

        $data['title'] = 'Daftar Data Transaksi';
        $data['list_data'] = $this->mpemesanan->select_data_det($id);
        $data['list_data_det'] = $this->mpemesanandet->detail_data($id);
        $data['isi'] = 'isi_det';
        $this->load->view('template_admin', $data);
    }

    function update_status($id = NULL, $status = NULL, $roll=NULL) {
//        if($status==2)
//            $status_kirim="1";
//        else 
//            $status_kirim="0";

        $data = array(
            'status' => $status,
            'status_pengiriman' => 0
        );
        $this->mpemesanan->update($data, $id);


        $dta = $this->mpemesanandet->where("id_pemesanan = '$id'")->get();
        if ($status == 2) {
            foreach ($dta as $dt_pesan) {
                $id_produk_det = $dt_pesan->id_produk_det;
                $bny = $dt_pesan->bnyk;

                $this->mprodukdet->update_produk($id_produk_det, $bny);
            }
        }
        if ($roll == 22) {
            foreach ($dta as $dt_pesan) {
                $id_produk_det = $dt_pesan->id_produk_det;
                $bny = $dt_pesan->bnyk;

                $this->mprodukdet->roll_update_produk($id_produk_det, $bny);
            }
        }



        $this->index();
    }

    function delete($id) {
        $this->mpemesanan->delete($id);
        redirect("admin_transaksi");
    }

}

?>
